package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.enumType.MmochatObjectType;
import com.dragon.mmochat.model.enumType.MmochatShopType;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_13_4S extends SkymobiProtocolMessage {
	int hallState;
	MmochatShopType shopType;
	int version; // 版本号
	boolean useInputBox = true; // 是否使用数量输入框
	String title; // 标题
	int money; // 玩家拥有的钱
	MmochatObjectType objType; // 物品类型
	List<ShopObjInfo> shopObjs = new ArrayList<ShopObjInfo>(); // 出售物品

	public Mmochat_13_4S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_13_4);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putUnsignedShort(hallState);
		out.put((byte) shopType.getKey());
		out.putInt(version);
		if (useInputBox) {
			out.put((byte) 1);
		} else {
			out.put((byte) 0);
		}
		out.putPrefixedString(title, 1);
		out.putInt(money);
		out.putInt(objType.getValue());
		out.put((byte) shopObjs.size());
		for (ShopObjInfo obj : shopObjs) {
			out.putInt(obj.getKey());
			out.putInt(obj.getEquipLevel());
			out.putUnsignedShort(obj.getBmpId());
			out.putPrefixedString(obj.getSellInfo(), 2);
		}
	}

	public void setHallState(int hallState) {
		this.hallState = hallState;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public void addShopObj(ShopObjInfo obj) {
		shopObjs.add(obj);
	}

	public void setShopObjs(List<ShopObjInfo> shopObjs) {
		this.shopObjs = shopObjs;
	}

	public void setUseInputBox(boolean useInputBox) {
		this.useInputBox = useInputBox;
	}

	public void setObjType(MmochatObjectType objType) {
		this.objType = objType;
	}

	public void setShopType(MmochatShopType shopType) {
		this.shopType = shopType;
	}

	public class ShopObjInfo {
		private int key;
		private int equipLevel = 0; // 只有装备需要此项
		private int bmpId;
		private String sellInfo;

		public int getKey() {
			return key;
		}

		public void setKey(int key) {
			this.key = key;
		}

		public int getBmpId() {
			return bmpId;
		}

		public void setBmpId(int bmpId) {
			this.bmpId = bmpId;
		}

		public String getSellInfo() {
			return sellInfo;
		}

		public void setSellInfo(String sellInfo) {
			this.sellInfo = sellInfo;
		}

		public int getEquipLevel() {
			return equipLevel;
		}

		public void setEquipLevel(int equipLevel) {
			this.equipLevel = equipLevel;
		}

	}
}